{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "05e6f22f",
   "metadata": {},
   "source": [
    "# IIR脉冲响应不变法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e96d3eba",
   "metadata": {},
   "source": [
    "利用脉冲响应不变变换法，把下列模拟域的模拟滤波器转换为数字滤波器，采样周期T=1。\n",
    "\n",
    "    H(s)=(s+1)/(s^2+5s+6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4a329dfb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([ 1.       , -0.2208835]),\n",
       " array([ 1.        , -0.18512235,  0.00673795]))"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#library\n",
    "import numpy as np\n",
    "from scipy import signal\n",
    "\n",
    "#analog filter transfer function\n",
    "b_analog = np.array([1,1]) #numerator\n",
    "a_analog = np.array([1,5,6]) #denominator\n",
    "T = 1 #sampling period\n",
    "\n",
    "#impulse response invariable method\n",
    "r,p_analog,k = signal.residue(b_analog,a_analog) \n",
    "#r is coefficient, p_analog is pole in analog\n",
    "p_digital = np.exp(p_analog*T) #p_digital is pole in digital\n",
    "a_digital,b_digital = signal.invresz(r,p_digital,k)\n",
    "a_digital,b_digital #display values of denominator and numerator\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f66b0920",
   "metadata": {},
   "source": [
    "对应Z域的系统函数为\n",
    "\n",
    "    H(z)=(1-0.2208835z^(-1))/(1-0.18512235z^(-1)+0.00673795z^(-2) )\t\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
